<?php
declare (strict_types = 1);

namespace app\admin\validate;

use think\Validate;

class Goods extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名' =>  ['规则1','规则2'...]
     *
     * @var array
     */
    protected $rule = [
        'title'            => 'require',
        'category_id'      => 'require|number',
        'category_path_id' => 'require',
        'stock'            => 'number',
        'price'            => 'float',
        'cost_price'       => 'float',
        'is_show_stock'    => 'require|in:0,1',
        // 'big_image'        => '',
        'recommend_image'  => 'require',
        'carousel_image'   => 'require',
        'description'      => 'require',
        'production_time'  => 'require',
        'goods_specs_type' => 'require|in:1,2',
    ];

    /**
     * 定义错误信息
     * 格式：'字段名.规则名' =>  '错误信息'
     *
     * @var array
     */
    protected $message = [
        'title.require'            => '商品名称不能为空',
        'category_id.require'      => '商品分类不可为空',
        'category_id.number'       => '商品分类错误',
        'category_path_id.require' => '商品分类不可为空',
        'promotion_title.require'  => '促销语不可为空',
        'goods_unit.require'       => '商品单位不可为空',
        'keywords.require'         => '关键词不可为空',
        'sub_title.require'        => '副标题不可为空',
        'stock.number'             => '库存格式错误',
        'price.float'              => '销售价格格式错误',
        'cost_price.float'         => '市场价格格式错误',
        'is_show_stock.require'    => '库存是否显示必须',
        'is_show_stock.in'         => '库存是否显示值错误',
        // 'big'
        'recommend_image.require'  => '展示图不可为空',
        'carousel_image.require'   => '轮播图不可为空',
        'description.require'      => '商品详情不可为空',
        'production_time.require'  => '生产日期不可为空',
        'goods_specs_type.require' => '商品规格错误',
        'goods_specs_type.in'      => '商品规格错误'
    ];
}
